/**
 * 主框架tabs对象
 */
var WIN_TAB = window.parent.$.ligerui.get('framecenter');
// common
function GetRequest() {
	var url = location.search;
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}
/*
 * 在列表页中传递标签ID参数，如"&pTabid="+WIN_TAB.getSelectedTabItemID();
 * 在新建和编辑标签页面的“确定”或“提交”按钮中调用，关闭标签页和刷新列表页
 */
function close_liger_tab() {
	// reflash parent tab
	var params = GetRequest();
	var parentid = params['pTabid'];
	var ctid = WIN_TAB.getSelectedTabItemID();
	if (parentid) {
		WIN_TAB.selectTabItem(parentid);
		WIN_TAB.reload(parentid);
	}
	// close tab
	WIN_TAB.removeTabItem(ctid);
}
function reload_cur_tab() {
	WIN_TAB.reload(WIN_TAB.getSelectedTabItemID());
}

// 关闭当前选项卡(不刷新上上一个父节点)
function close_tab_no_refresh() {
	var params = GetRequest();
	var ctid = WIN_TAB.getSelectedTabItemID();
	var parentid = params['pTabid'];
	if (parentid) {
		WIN_TAB.selectTabItem(parentid);
	}
	WIN_TAB.removeTabItem(ctid);
}

/**
 * 调整liger grid的空格
 * 
 * @param grid
 */
/*
 * 已经加入源代码 function f_ajustGrid(grid){ var gid = grid.id, gw=$('#'+gid).width(),
 * isck = grid.options.checkbox, cols = grid.get('columns'); var cleng =
 * cols.length, csum = 0; for(var i=0;i<cleng;i++){
 * console.log(cols[i]._width,i); csum += parseInt(cols[i]._width); } function
 * haveZoom(gridWidth, colsWidth, ischeck){ if(ischeck) return gridWidth-56 >
 * colsWidth; else return gridWidth-26 > colsWidth; } function calInc(gleng,
 * coleng, colnum, ischeck){ if(ischeck) return Math.floor((gw-csum-70)/cleng);
 * else return Math.floor((gw-csum-40)/cleng); } if(haveZoom(gw, csum, isck)){
 * var inc = calInc(gw, csum, cleng, isck); for(var j=0;j<cleng;j++){
 * cols[j].width = cols[j]._width + inc; delete cols[j]._width; }
 * grid.set('columns', cols); grid.reRender(); } }
 */
$(function() {
	/**
	 * 用户提交表单等待状态
	 */
	/*
	 * var ctid = WIN_TAB.getSelectedTabItemID(); if(ctid){ var $t =
	 * window.parent.$('div[tabid="'+ctid+'"]'); var tl = $('.l-tab-loading',
	 * $t)[0]; } $(document).ajaxSend(function(){ tl &&
	 * $(tl).css('display','block'); }); $(document).ajaxComplete(function(){ tl &&
	 * $(tl).css('display','none'); });
	 */
	/**
	 * 修复弹出的窗口显示在文字提示后面的BUG
	 */
	$.ligerui.win.setFront = function(win) {
		var wins = $.ligerui.find($.ligerui.core.Win);
		for (var i in wins) {
			var w = wins[i];
			if (w == win) {
				$(w.element).css("z-index", "10002");
				this.activeTask(w);
			} else {
				$(w.element).css("z-index", "10001");
			}
		}
	};
	/**
	 * 关键字过滤ajax提交时返回的页面
	 */
	var pathName = document.location.pathname;
	var index = pathName.substr(1).indexOf("/");
	var BasePath = pathName.substr(0, index + 1);
	$.ajaxSetup({
		async : false,
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		complete : function(XMLHttpRequest, textStatus) {
			var banKeywords = XMLHttpRequest.getResponseHeader("banKeywords"); // 通过XMLHttpRequest取得响应头，sessionstatus，
			var banKeywordsValueEncode = XMLHttpRequest
					.getResponseHeader("banKeywordsValue"); // 通过XMLHttpRequest取得响应头，sessionstatus，
			if (banKeywords == 'banKeywords') {
				var banKeywordsValue = encodeURI(banKeywordsValueEncode);
				// 如果超时就处理 ，指定要跳转的页面
				window.location
						.replace(BasePath
								+ "/manager/system/systemmanager/banKeywords.do?banKeywords="
								+ banKeywordsValue);
			}
		}
	});
});
function sync_grid1(gridid) {
	var tbl1 = $('tr', $('#' + gridid + ' .l-grid-body1')), tbl2 = $('tr',
			$('#' + gridid + ' .l-grid-body2'));
	for (var i = 0; i < tbl2.length; i++) {
		$(tbl1[i]).height($(tbl2[i]).height());
	}
}